public class MyMath { /** * Returns the absolute value of x * * @param x An integer for which to find the absolute value * * @result The absolute value of x, as an integer */ public static int abs( int x ) { // DECLARE VARIABLES/DATA DICTIONARY int absX; // RESULT: the absolute value of x // BODY OF ALGORITHM if ( x >= 0 ) { absX = x; } else { absX = -x; } // RETURN RESULT return absX; } /** * Performs exponentiation by raising x to the power of y. * * @param x Base of exponentiation * @param y Power of exponentiation * * @result x to the power of y, as an integer */ public static int pow( int x, int y ) { // DECLARE VARIABLES/DATA DICTIONARY int xToY; // RESULT: x raised to the power y int count; // INTERMEDIATE: counts the number of multiplcations // BODY OF ALGORITHM xToY = 1; count = 1; while ( count <= y ) { xToY = xToY * x; count = count + 1; } // RETURN RESULT return xToY; } }